# class Washer:
#     height = 800
#
# # 查看类属性
# print(Washer.height)
#
# # 新增类属性
# Washer.width = 500
# print(Washer.width)
#
# wa = Washer()
# print(wa)
# wa2 = Washer()
# print(wa2)

# 实例方法和实例属性
# 实例方法
# 由对象调用，至少有一个self参数，执行实例方法的时候，自动将调用该方法的对象赋值给self
class Washer:
    height = 800

    def wash(self):
        print('wash')
        print(self)

wa = Washer()
print(wa)
wa.wash()

# 实例属性
class Person:
    name = 'hello'
    def introduce(self):
        print(Person.name)
        print(self.name,p.age)

p = Person()
p.age = 18
p.introduce()
# 类属性与实例属性的区别
# 类属性时公共的，实例属性是属于对象的私有的只能由对象名访问


# 构造函数 __init__()
# 用来做属性初始化和赋值操作，类实例化会自动被调用
# class Test:
#     def __init__(self):
#         print('test')
# test = Test()
#
# class Student:
#     def __init__(self):
#         self.name = 'hello World'
#         self.age = 18
#     def introduce(self):
#         print(self.name,self.age)
#
# stu = Student()
# stu.introduce()

# 析构函数__del__()
# 正常运行时不会调用__del__函数,对象执行结束之后，系统过自动调用__del__放啊放

class Person:
    def __init__(self):
        print('__init__')
    def __del__(self):
        print('__del__')
p = Person()
del p
print('last')